package com.yanqu.road.entity.autodata.task;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.autodata.AutoDataObject;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_u_object_task", desc = "指定对象任务")
public class UserObjectTaskData extends AutoDataObject {
    @FieldTypeAnnotation(desc = "玩家id", select = true, isIndex = true, update = true)
    private long userId;
    @FieldTypeAnnotation(desc = "完成类型", isIndex = true, update = true)
    private int completeType;
    @FieldTypeAnnotation(desc = "对象id", isIndex = true, update = true)
    private int objectId;
    @FieldTypeAnnotation(desc = "已完成的任务id")
    private List<Integer> finishIds = new ArrayList<>();
    @FieldTypeAnnotation(desc = "进度值")
    private BigInteger value= BigInteger.ZERO;
    @FieldTypeAnnotation(desc = "特殊参数")
    private String param="";
    @FieldTypeAnnotation(desc = "最近数据更新时间")
    private long lastUpdateTime;

    public UserObjectTaskData() {
    }

    public UserObjectTaskData(long userId, int objectId, int completeType) {
        this.userId = userId;
        this.objectId = objectId;
        this.completeType = completeType;
        setInsertOption();
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getObjectId() {
        return objectId;
    }

    public void setObjectId(int objectId) {
        this.objectId = objectId;
    }

    public int getCompleteType() {
        return completeType;
    }

    public void setCompleteType(int completeType) {
        this.completeType = completeType;
    }

    public List<Integer> getFinishIds() {
        return finishIds;
    }

    public void setFinishIds(List<Integer> finishIds) {
        this.finishIds = finishIds;
        setUpdateOption();
    }

    public BigInteger getValue() {
        return value;
    }

    public void setValue(BigInteger value) {
        this.value = value;
        setUpdateOption();
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
        setUpdateOption();
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
        setUpdateOption();
    }

    public void addFinishTaskId(Integer taskId) {
        if (finishIds.contains(taskId)) {
            return;
        }
        List<Integer> tempList = new ArrayList<>(finishIds);
        tempList.add(taskId);
        setFinishIds(tempList);
        setLastUpdateTime(DateHelper.getCurrentTime());
    }

    public boolean isFinish(Integer taskId) {
        return finishIds.contains(taskId);
    }
}
